from flask import request, g
from common import ApiResponse
import logging
import re
from datetime import datetime, timedelta


def register_hook(app):
    """拦截器(钩子函数)注册"""

    @app.before_request
    def before_every_request():
        from ExtendRegister.model_register import User

        user = User()
        user.id = 1
        user.username = "OpenEssay"
        user.headimg = ""
        user.vip_start_at = datetime.now() + timedelta(days=365)
        user.vip_expire_at = datetime.now() - timedelta(days=1)

        g.userid = user.id
        g.user = user
        g.isVip = True
